package com.ruoyi.fapiao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fapiao.domain.FapiaoInfo;
import com.ruoyi.fapiao.service.IFapiaoInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * fapiaoController
 * 
 * @author xxxmatata
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/fapiao/fapiao")
public class FapiaoInfoController extends BaseController
{
    @Autowired
    private IFapiaoInfoService fapiaoInfoService;

    /**
     * 查询fapiao列表
     */
    @PreAuthorize("@ss.hasPermi('fapiao:fapiao:list')")
    @GetMapping("/list")
    public TableDataInfo list(FapiaoInfo fapiaoInfo)
    {
        startPage();
        List<FapiaoInfo> list = fapiaoInfoService.selectFapiaoInfoList(fapiaoInfo);
        return getDataTable(list);
    }

    /**
     * 导出fapiao列表
     */
    @PreAuthorize("@ss.hasPermi('fapiao:fapiao:export')")
    @Log(title = "fapiao", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FapiaoInfo fapiaoInfo)
    {
        List<FapiaoInfo> list = fapiaoInfoService.selectFapiaoInfoList(fapiaoInfo);
        ExcelUtil<FapiaoInfo> util = new ExcelUtil<FapiaoInfo>(FapiaoInfo.class);
        util.exportExcel(response, list, "fapiao数据");
    }

    /**
     * 获取fapiao详细信息
     */
    @PreAuthorize("@ss.hasPermi('fapiao:fapiao:query')")
    @GetMapping(value = "/{fapiaoId}")
    public AjaxResult getInfo(@PathVariable("fapiaoId") Long fapiaoId)
    {
        return success(fapiaoInfoService.selectFapiaoInfoByFapiaoId(fapiaoId));
    }

    /**
     * 新增fapiao
     */
    @PreAuthorize("@ss.hasPermi('fapiao:fapiao:add')")
    @Log(title = "fapiao", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FapiaoInfo fapiaoInfo)
    {
        return toAjax(fapiaoInfoService.insertFapiaoInfo(fapiaoInfo));
    }

    /**
     * 修改fapiao
     */
    @PreAuthorize("@ss.hasPermi('fapiao:fapiao:edit')")
    @Log(title = "fapiao", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FapiaoInfo fapiaoInfo)
    {
        return toAjax(fapiaoInfoService.updateFapiaoInfo(fapiaoInfo));
    }

    /**
     * 删除fapiao
     */
    @PreAuthorize("@ss.hasPermi('fapiao:fapiao:remove')")
    @Log(title = "fapiao", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fapiaoIds}")
    public AjaxResult remove(@PathVariable Long[] fapiaoIds)
    {
        return toAjax(fapiaoInfoService.deleteFapiaoInfoByFapiaoIds(fapiaoIds));
    }
}
